package com.stage_1.module_4;

public class Runner implements Runnable {
    //剩余票数
    private int x;

    public Runner() {
    }

    public Runner(int x) {
        this.x = x;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    @Override
    public synchronized void run() {
        while(true){
            int t = getX();

            if(t>0){
                System.out.println("正在出票……");
                t--;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("请取走你的票。目前剩余票数为："+t);
            }else{
                System.out.println("不好意思！票已售罄！");
                break;
            }
            setX(t);
        }


    }
}
